import { Extension, Node } from '@valuation/core';
import { hello, hello1 } from './command';
import {Plugin, PluginKey} from "@valuation/rivet";


/*

用途：Node attrs 用于存储与节点相关的元数据或配置信息。
数据类型：通常存储简单数据类型（如字符串、数字、 布尔值）或简单的对象。
位置：attrs 存储在节点本身上，作为节点的一个属性。
使用场景：适用于存储节点的配置信息，如样式、标识符、状态等

*/
/*
用途：Node Fragment 用于存储一组子节点，表示节点的内容。
数据类型：存储 Node 对象的集合。
位置：Fragment 作为节点的内容部分，存储在节点的 content 属性中。
使用场景：适用于存储节点的实际内容，如文本、其他嵌套节点等。
*/


// 基础 公共列定义
export const code = Node.create({
  name: 'code',
  desc: '编码',
});

export const unit = Node.create({
  name: 'unit',
  desc: '单位',
});

export const name = Node.create({
  name: 'name',
  desc: '名称',
});
export const projectAttr = Node.create({
  name: 'projectAttr',
  desc: '项目特征',
});

export const quantity = Node.create({
  name: 'quantity',
  desc: '工程量',
});
export const quantityExpression = Node.create({
  name: 'quantityExpression',
  desc: '工程量表达式',
});


// 分部分项 业务公共列字段定义 -------------------start------------------------------

export const sbfPrice = Node.create({
  name: 'sbfPrice',
  desc: '设备费单价',
});

export const sbfTotal = Node.create({
  name: 'sbfTotal',
  desc: '设备费合价',
});
export const zgfPrice = Node.create({
  name: 'zgfPrice',
  desc: '暂估单价',
});
export const zgfTotal = Node.create({
  name: 'zgfTotal',
  desc: '暂估合价',
});

export const zjfPrice = Node.create({
  name: 'zjfPrice',
  desc: '直接费单价',
});
export const zjfTotal = Node.create({
  name: 'zjfTotal',
  desc: '直接费合价',
});
export const rfee = Node.create({
  name: 'rfee',
  desc: '人工费单价',
});
export const totalRfee = Node.create({
  name: 'totalRfee',
  desc: '人工费合价',
});
export const cfee = Node.create({
  name: 'cfee',
  desc: '材料费单价',
});
export const totalCfee = Node.create({
  name: 'totalCfee',
  desc: '材料费合价',
});
export const jfee = Node.create({
  name: 'jfee',
  desc: '机械费单价',
});
export const totalJfee = Node.create({
  name: 'totalJfee',
  desc: '机械费合价',
});
export const profitFee = Node.create({
  name: 'profitFee',
  desc: '利润费单价',
});
export const totalProfitFee = Node.create({
  name: 'totalProfitFee',
  desc: '利润费合价',
});
export const managerFee = Node.create({
  name: 'managerFee',
  desc: '管理费单价',
});
export const totalManagerFee = Node.create({
  name: 'totalManagerFee',
  desc: '管理费合价',
});
export const zcfee = Node.create({
  name: 'zcfee',
  desc: '主材费单价',
});
export const totalZcfee = Node.create({
  name: 'totalZcfee',
  desc: '主材费合价',
});

export const price = Node.create({
  name: 'price',
  desc: '工程造价单价',
});
export const total = Node.create({
  name: 'total',
  desc: '工程造价合价',
});


export const gfPrice = Node.create({
  name: 'gfPrice',
  desc: '规费单价',
});
export const gfTotal = Node.create({
  name: 'gfTotal',
  desc: '规费合价',
});
export const scgjsyfPrice = Node.create({
  name: 'scgjsyfPrice',
  desc: '生产工具使用费单价',
});
export const scgjsyfTotal = Node.create({
  name: 'scgjsyfTotal',
  desc: '生产工具使用费合价',
});
export const fhddglzjfPrice = Node.create({
  name: 'fhddglzjfPrice',
  desc: '繁华地段管理增加费单价',
});
export const fhddglzjfTotal = Node.create({
  name: 'fhddglzjfTotal',
  desc: '繁华地段管理增加费合价',
});
export const gjfhfPrice = Node.create({
  name: 'gjfhfPrice',
  desc: '冬季防寒费单价',
});
export const gjfhfTotal = Node.create({
  name: 'gjfhfTotal',
  desc: '冬季防寒费合价',
});
export const sdghzjfPrice = Node.create({
  name: 'sdghzjfPrice',
  desc: '山地管护增加费单价',
});
export const sdghzjfTotal = Node.create({
  name: 'sdghzjfTotal',
  desc: '山地管护增加费合价',
});
export const lssgaqfhcsfPrice = Node.create({
  name: 'lssgaqfhcsfPrice',
  desc: '绿色施工安全防护措施费单价',
});
export const lssgaqfhcsfTotal = Node.create({
  name: 'lssgaqfhcsfTotal',
  desc: '绿色施工安全防护措施费合价',
});

export const jxsePrice = Node.create({
  name: 'jxsePrice',
  desc: '进项税额单价',
});

export const jxseTotal = Node.create({
  name: 'jxseTotal',
  desc: '进项税额合价',
});

export const xxsePrice = Node.create({
  name: 'xxsePrice',
  desc: '销项税额单价',
});

export const xxseTotal = Node.create({
  name: 'xxseTotal',
  desc: '销项税额合价',
});

export const zzsynsePrice = Node.create({
  name: 'zzsynsePrice',
  desc: '增值税应纳税额单价',
});

export const zzsynseTotal = Node.create({
  name: 'zzsynseTotal',
  desc: '增值税应纳税额合价',
});
export const fjsePrice = Node.create({
  name: 'fjsePrice',
  desc: '附加税费单价',
});
export const fjseTotal = Node.create({
  name: 'fjseTotal',
  desc: '附加税费合价',
});
export const sqgczjPrice = Node.create({
  name: 'sqgczjPrice',
  desc: '税前工程造价单价',
});
export const sqgczjTotal = Node.create({
  name: 'sqgczjTotal',
  desc: '税前工程造价合价',
});
export const fxfyPrice = Node.create({
  name: 'fxfyPrice',
  desc: '风险费用单价',
});
export const fxfyTotal = Node.create({
  name: 'fxfyTotal',
  desc: '风险费用合价',
});
export const sjPrice = Node.create({
  name: 'sjPrice',
  desc: '税金单价',
});
export const sjTotal = Node.create({
  name: 'sjTotal',
  desc: '税金合价',
});

// 分部分项 基础属性字段定义 -------------------end------------------------------
// 公共节点数组
export const nodes = [
  code, unit, name, projectAttr, quantity, quantityExpression,
  sbfPrice, sbfTotal, zgfPrice, zgfTotal, zjfPrice, zjfTotal, rfee, totalRfee,
  cfee, totalCfee, jfee, totalJfee, profitFee, totalProfitFee, managerFee,
  totalManagerFee, zcfee, totalZcfee, price, total, gfPrice, gfTotal,
  scgjsyfPrice, scgjsyfTotal, fhddglzjfPrice, fhddglzjfTotal, gjfhfPrice,
  gjfhfTotal, sdghzjfPrice, sdghzjfTotal, lssgaqfhcsfPrice, lssgaqfhcsfTotal,
  jxsePrice, jxseTotal, xxsePrice, xxseTotal, zzsynsePrice, zzsynseTotal,
  fjsePrice, fjseTotal, sqgczjPrice, sqgczjTotal, fxfyPrice, fxfyTotal,
  sjPrice, sjTotal,
];
// 公共节点的名称
export const nodeNames = nodes.map((node) => node.name);
const ns = nodeNames.join(' ');

// 代表分部分项 措施项目的每一行数据
export const TREE = Node.create({
  name: 'treeNode',
  desc: '节点',
  content: `${ns} children`,
  addAttributes() {
    // 基础元数据定义 是否为补充  是否是标准
    return {
      isStandard: { default: 0 }, // shf 0 补充 1 标准
      standardId: { default: null }, // 是标准的情况会有值
      isCostDe: { default: 0 },
      kind: { default: 0 },
    };
  },
  // 一版用作前端返回数据 不做任何逻辑
  render() {
    return {};
  },
});


export const CHILDREN = Node.create({
  name: 'children',
  desc: '子节点',
  content: 'treeNode*',
});
/* 单位编辑区公共属性 */
export const CommonAttr = Extension.create({
  name: 'CommonAttr',
  desc: '分部分项，措施项目公共属性',
  addCommands() {
    return {
      hello,
      hello1,
    };
  },
  addGlobalAttributes() {
    return [
      {
        types: nodeNames,
        attributes: {
          value: { default: 0 },
        },
      },
    ];
  },
  addRivetPlugins() {
    return [new Plugin({key: new PluginKey('CommonAttr',"公共属性"), state: {
       init:async ()=>{return {name:"aaa"};},apply:async ()=>{
      return {name:"aaa"};
        } },})];
  },
});
